package com.qk.management.service.Impl;

import ch.qos.logback.core.util.Loader;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author 16778
 * @date 2025/9/29 10:31
 * @description
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;


    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.InsertDept(dept);
    }

    @Override
    public PageResult<Dept> page(String name, Integer status, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
//        Long total = deptMapper.count(name,status);
//        int offset = (page-1)*pageSize;
        List<Dept> rows = deptMapper.list(name,status);
        Page<Dept> deptPage = (Page<Dept>) rows;
        return PageResult.<Dept>builder()
                .total(deptPage.getTotal())
                .rows(deptPage.getResult())
                .build();
    }

    @Override
    public Dept getInfo(Integer id) {
        Dept dept = deptMapper.selectById(id);
        return dept;
    }

    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }

    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }
}
